#ifndef AWGET_H
#define AWGET_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h> //Provides string functions
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>

#define MAX_IP_ADDRESS_LENGTH 15
typedef unsigned char byte;
typedef unsigned short packLength;
//success values:
//0-failure (no file found)
//1-success (file exists)
//2-this SS is the destination (and file found)
struct ipPortPair{
  char ip[MAX_IP_ADDRESS_LENGTH];
  int port;
  char portC[6];
  int success;
};

struct data_msg {		 //
	char version; 		 //  -  1 byte (char) of Version data
	unsigned int data;       //  -  Unsigned 32 bit number (unsigned int) passed via a Client
}__attribute__((__packed__));	 //  -  PACKED. So its as small as possible w/ respect to its bits.


int openTCPsocket(char * hostname, char * port);

void printByteArray(int totalSize, byte* byteArray, int URL_LEN);

void printFileByteArray(byte* byteArray);
void printChainList(byte * byteArray, int totalSize, int URL_LEN);

void receiveFile(int sockfd, byte * byteArray, int urlFileSize);

int extractIPAddress(struct ipPortPair * nextSS, byte * byteArray, int randomSS);
void extractPort(struct ipPortPair *nextSS, byte * byteArray, int startIndex, int totalSize);
void decrementSSNum(byte * byteArray);
int getRandomNumber(int entries);
void saveFileToDisk(byte * byteArray, int urlFileSize);

#endif